package com.fangcang.controller;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.fangcang.pdf.PdfUtils;

@Controller
@RequestMapping("/exporter")
public class PdfExporterController {

	@RequestMapping("/pdf")
	public ResponseEntity<byte[]> exportToPdf(){
		HttpHeaders headers = new HttpHeaders();
		
		byte[] byteArray = PdfUtils.makePdfFile("");
		String fileName;
		try {
//			final byte[] bytes = byteArray;
			
//			System.out.println(new String(bytes, "utf-8"));
			fileName = URLEncoder.encode("分销商传真.pdf", "UTF-8");
			headers.setContentDispositionFormData("attachment", fileName);
			headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return new ResponseEntity<byte[]>(byteArray, headers, HttpStatus.OK);
	}
}
